package com.mashibing.singleton;

/**
 * 效率不高
 */
public class Mgro5 {
  public static volatile Mgro5 INSTANCE;
  private Mgro5(){}
  public static synchronized Mgro5 getInstance(){
      if (INSTANCE==null){
          //双重检查
          synchronized (Mgro5.class){
              if (INSTANCE==null){
                  try{
                      Thread.sleep(1);
                  }catch (InterruptedException e){
                      e.printStackTrace();
                  }
                  INSTANCE=new Mgro5();
              }
          }

      }
      return INSTANCE;
  }
    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            new Thread(()->{
                System.out.println(Mgro5.getInstance().hashCode());
            }).start();
        }
    }
}
